package com.yilin.platform.controller;

import com.yilin.platform.service.IAliPayService;
import com.yilin.platform.service.IBankCmbcService;
import com.yilin.platform.service.IBankPabService;
import com.yilin.platform.service.IWeChatService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
public class ApplicationTaskTime {
    private  Logger logger = LoggerFactory.getLogger(ApplicationTaskTime.class);

    @Resource
    IBankCmbcService cmbcService;
    @Resource
    IBankPabService pabService;
    @Resource
    IAliPayService aliPayService;

    @Autowired
    private IWeChatService weChatService;


    @Scheduled(fixedRate = 10000)//每隔多少时间开始执行
    public void cronTask() {

    }

    @Scheduled(fixedDelay = 3*60*1000) //等全部任务结束才会开始下次执行时间
    public void myTask3Minute() {
        try {//"民生银行单笔查询
            cmbcService.myTaskOneMinute();
        } catch (Exception e) {
            logger.info("民生银行单笔转账查询异常："+e.getMessage());
        }
        try {//"平安银行单笔查询
            pabService.dealSingleQueryTrade();
        } catch (Exception e) {
            logger.info("平安银行单笔查询异常："+e.getMessage());
        }
        try {//"支付宝支付询
            aliPayService.myTaskOneMinute();
        } catch (Exception e) {
            logger.error("支付宝支付询查询异常："+e.getMessage());
        }
        try {//"微信支付支付
            weChatService.myTaskOneMinute();
        } catch (Exception e) {
            logger.error("微信支付支付询查询异常："+e.getMessage());
        }

    }

    @Scheduled(fixedDelay = 10*60*1000)//等全部任务结束才会开始下次执行时间
    public void myTask20Minute() {
        try {//民生银行多笔查询
            cmbcService.myTaskOneMinuteBatch();
        } catch (Exception e) {
            logger.info("民生银行批量转账查询异常："+e.getMessage());
        }
        try {//民生银行多笔代发工资，费用报销查询
            cmbcService.myTaskOneMinuteBehalfBatch();
        } catch (Exception e) {
            logger.info("民生银行批量代发工资，费用报销查询异常："+e.getMessage());
        }
        try {//平安银行多笔查询
            pabService.dealBatchQueryTrade();
        } catch (Exception e) {
            logger.info("平安银行多笔查询异常："+e.getMessage());
        }
    }

    @Scheduled(cron = "0 0 0 * * ?")
    public void executeTask() {
        try {//平安银行支付退票查询
            pabService.taskReqPaymentRefundQuery(1);
        } catch (Exception e) {
            logger.info("平安银行支付退票查询异常："+e.getMessage());
        }
    }



}

